package com.iot08.api.service;

import com.alibaba.fastjson.JSONObject;
import com.iot08.common.entity.app.DevQQConfig;
import com.iot08.common.service.base.BaseService;
import com.iot08.common.utils.DateUtil;
import com.iot08.common.utils.StringUtil;
import lombok.extern.slf4j.Slf4j;
import org.bson.types.ObjectId;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.data.mongodb.core.query.Update;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * @version 1.0
 * @Description:
 * @author: Weichao
 * @time: 2021/9/6 17:24
 */
@Slf4j
@Service
public class DevQQConfigService extends BaseService<DevQQConfig> {

    /**
     * @param imei
     * @param GUID
     * @param GuidFilePath
     * @param licenseld
     * @param licenseldFilePath
     * @time: 2021/9/6 19:48
     * @author: Weichao
     * @version 1.0
     */
    public void add(String imei, String GUID, String GuidFilePath, String licenseld, String licenseldFilePath) {
        DevQQConfig devQQConfig = new DevQQConfig();
        devQQConfig.setId(imei);
        devQQConfig.setGuid(GUID);
        devQQConfig.setGuidFilePath(GuidFilePath);
        devQQConfig.setLicenseld(licenseld);
        devQQConfig.setLicenseldFilePath(licenseldFilePath);
        devQQConfig.setCreatDate(new Date());
        //保存记录
        this.save(devQQConfig);
    }

    /**
     * 更新
     * @param imei
     * @param upDataMap
     */
    public void update(String imei, JSONObject upDataMap) {
        Update update = new Update();
        for (String key : upDataMap.keySet()){
            update.set(key, upDataMap.get(key));
        }
        update.set("updateDate", new Date());
        this.updateById(imei, update);
    }

}
